package edu.gatech.oad.mule;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

/**
 * This class is responsible for displaying the GUI so players can set up 
 * their game of MULE.  After the Players have set up their game, this class 
 * will pass the setup parameters into GameDriver so GameDriver can begin to 
 * set up the game of MULE.
 *
 * @author Brendan McGarry, Dale Avery, D'Miria Collins, Natasha Parekh, Jaemin Park
 * @version %I%, %G%
 */
public class Configuration{
	
	//title of the JFrame	
	public final String FRAME_TITLE = "M.U.L.E by Team 24 - Configure";

	/**
	 * This constructor creates configuration GUI for the users to set 
	 * up the game of MULE
	 */
	public Configuration(){
		System.out.println("configuration");
		//call the SwingUtilities to make the JFrame when it's ready.
		//  you need to do this to ensure the "job" is placed on the 
		//  Event Dispatch Thread (EDT).
		//
		//We do this because some Swing component methods are 
		//  labelled "thread safe" in the API specification; these 
		//  can be safely invoked from any thread. All other Swing 
		//  component methods must be invoked from the event 
		//  dispatch thread. Programs that ignore this rule may 
		//  function correctly most of the time, but are subject 
		//  to unpredictable errors that are difficult to reproduce.
		//
		//Better safe than sorry, you know?
		SwingUtilities.invokeLater(new Runnable(){
			@Override
			public void run(){
				//create the GUI when you're ready
				displayGUI();
			}//end run
		});
		System.out.println("/configuration");
	}//end constructor
	
	/**
	 * This method is called by the event dispatch thread.  It 
	 * creates the GUI for the user to see and set up the game.
	 */
	public void displayGUI(){
		System.out.println("displayGUI");
		//create a new JFrame to hold our configuration screen
		JFrame frame = new JFrame(FRAME_TITLE);
		//if the user clicks the red x, we go bye-bye
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//add the configuration GUI
		frame.add(new ConfigurationPanel());
		//arrange all the components as nice as you can
		frame.pack();
		//put the JFrame in the center of the screen
		frame.setLocationRelativeTo(null);
		//cannot resize
		frame.setResizable(false);	
		//it's helpful to see the frame... you know?
		frame.setVisible(true);
		System.out.println("/displayGUI");
	}//end displayGUI
}//end class Configuration
